/** * Created by Administrator on 2018-11-26. */public class Test1 {    public static void main(String[] args) throws InterruptedException{        Thread t1 = new Thread(){            @Override            public void run(){                while (true){                    if(Thread.currentThread().isInterrupted()){                        System.out.println("Interruted!");                        break;                    }                    try{                       Thread.sleep(3000);                       System.out.println("sleeping...");                    }catch (InterruptedException e){                        System.out.println("Interruted when sleep");                        Thread.currentThread().interrupt();                    }                   // Thread.yield();                }            }        };        t1.start();        Thread.sleep(2000);        System.out.println("stop");        t1.interrupt();    }}